package thread;

import java.util.concurrent.Callable;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.FutureTask;

/**
 * 实现Callable
 */
class MyCallable implements Callable<String> {
    @Override
    public String call() throws Exception {
        return "hello world";//线程执行后返回的结果
    }
}
public class ThreadDemo3 {
    public static void main(String[] args) throws ExecutionException, InterruptedException {
        MyCallable myCallable = new MyCallable();
        FutureTask<String> futureTask = new FutureTask<>(myCallable);
        Thread thread = new Thread(futureTask);
        thread.start();
        System.out.println("打招呼: "+futureTask.get());//调用get()方法获取返回值
    }
}
